package com.zx.controller;

import com.zx.entity.Product;
import com.zx.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author jack.wu
 * @version 1.0
 * @date 2020-03-08
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @Resource
    private ProductService productService;

    /**
     * 查询商品信息
     *
     * @param pid 商品id
     * @return 商品信息
     */
    @GetMapping("/product/{pid}")
    @ResponseStatus(HttpStatus.OK)
    public Product findById(@PathVariable("pid") Integer pid) {
        // 校验pid
        return productService.findById(pid);
    }

    /**
     * 查询商品信息
     *
     * @param pid 商品id
     * @return 商品信息
     */
    @GetMapping("/reduceInventory")
    @ResponseStatus(HttpStatus.OK)
    void reduceInventory(@RequestParam("pid") Integer pid, @RequestParam("num") int num){
        productService.reduceInventory(pid, num);
    }

}
